package com.cangchu.ui.activity;

import android.support.v4.app.Fragment;
import com.cangchu.R;
import com.cangchu.util.InjectView;

/**
 * fragment 复用Activity 基类，封装View 的初始化过程，对外提供Fragment 的实例创建接口
 * Created by Administrator on 2016/10/28.
 */
public abstract class SingleFragmentActivity extends BaseActivity<SingleFragmentActivity> {

    @InjectView(R.id.fragmentContainers)
    private Fragment fragment;

    //这里写死了对应的layout ，就说明会不停的复用。所有的SingleFragment都会使用同一个布局样式
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_singleFragment;
    }

    @Override
    protected void initViewsAndEvents() {

//        Fragment fragment = manager.findFragmentById(R.id.fragmentContainers);
        if (fragment == null) {
            fragment = createFragmen();
            getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainers, fragment).commit();
        }
    }

    protected abstract Fragment createFragmen();
}
